//
//  codeInputViewController.swift
//  SwitfTest
//
//  Created by runone02 on 2019/1/16.
//  Copyright © 2019年 liqiyun. All rights reserved.
//

import UIKit

class codeInputViewController: BaseViewController {
    private var codeBackString : String?
    override func viewDidLoad() {
        super.viewDidLoad()
        unowned let weakSelf = self
        self.title = "验证码输入框"
        var pythons = ["John","Michael","Graham","Terry","Eric","Terry"]
        pythons.removeAll {$0.hasPrefix("Terry")}  //移除数组中某个元素
//        print("剩下的数组元素" , pythons)
        
        //图形验证码
        let picCode = PicCodeView(frame: CGRect(x: 0, y: 100, width: SCREEN_WIDTH, height: 100))
       
        picCode.changeStringBlock = {(str:String)in
            weakSelf.codeBackString = str
        }
        
        view.addSubview(picCode)
        
        let code = CodeView(frame: CGRect(x: 63, y: 220, width: self.view.frame.size.width - 63*2, height: 40))
        
        code.Base.changeViewBasicAttributes(lineColor: UIColor.black, lineInputColor: UIColor.black, cursorColor: UIColor.blue, errorColor: UIColor.red, fontNum: UIFont.systemFont(ofSize: 17), textColor: UIColor.black)
        code.Base.changeInputNum(num: 4)
        
        ///判断输入是否正确
        code.callBacktext = { str in
            
            if(str.caseInsensitiveCompare(self.codeBackString!) == ComparisonResult.orderedSame){   ///不区分大小写
                if str == self.codeBackString {  //对比字符串
                    
                }
            }
             else {   //清空r输入框
                code.clearnText(error: "error")
                picCode.lodeNewView()
            }
        }
        view.addSubview(code)
    }

}
